cmake_minimum_required(VERSION 3.1)
project(MCME)

# We need ZLIB compression support.
find_package(ZLIB REQUIRED)

# Choose platform-specific implementation of dynamic loading.
if (UNIX)
  set(MCME_DL_SRC mcmeLoaderUNIX.cxx) # Unix & OS X
else ()
  set(MCME_DL_SRC mcmeLoaderWin.cxx) # Windows
endif ()

# Add library with components common to all executables.
add_library(mcme_base mcmeCompressor.cxx mcmeMath.cxx ${MCME_DL_SRC})
target_link_libraries(mcme_base PRIVATE ZLIB::ZLIB ${CMAKE_DL_LIBS})
install(TARGETS mcme_base DESTINATION lib)

# Add the main executable.
add_executable(mcme mcme.cxx)
target_link_libraries(mcme mcme_base)
install(TARGETS mcme DESTINATION bin)

# Optionally build a GUI.
option(MCME_BUILD_GUI "Build the MCME graphical user interface." ON)
if (MCME_BUILD_GUI)
  find_package(Qt4 REQUIRED QtGui)
  add_executable(mcme_gui mcme_gui.cxx)
  target_link_libraries(mcme_gui Qt4::QtGui)
endif ()
